﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebMediaTRApi.Controllers;
using WebMediaTRApi.WeatherForcasts;
using WebMediaTRApi.WeatherForcasts.Querys;

namespace WebMediaTRApi.Services
{
    public class WeatherForecastService
    {

        private static readonly string[] Summaries = new[]
            {
                "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
            };

        private readonly ILogger<WeatherForecastController> _logger;

        private List<WeatherForecast> weatherForecasts = new List<WeatherForecast>();

        public WeatherForecastService(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;

            weatherForecasts= Enumerable.Range(1, 50).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
           .ToList();

        }

        public IEnumerable<WeatherForecast> GetWeatherForecasts()
        {
            return weatherForecasts;
        }


        public WeatherForecast GetWeatherToday()
        {
            return  new WeatherForecast
            {
                Date = DateTime.Now.AddDays(2),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            };
        }


        public WeatherForecast CreateWeather(CreateWeatherCommand weatherCommand)
        {
            var forcast = new WeatherForecast();
            forcast.TemperatureC = weatherCommand.TemperatureC;
            forcast.Date = weatherCommand.Date;
            forcast.Summary = Summaries[Random.Shared.Next(Summaries.Length)];
            weatherForecasts.Add(forcast);
            return forcast;
        }
    }
}
